home *** CD-ROM | disk | FTP | other *** search
Text File | 2005-11-17 | 26.9 KB | 1,233 lines |
- Ôªøvar openPage = 1, flipped;
-
- /* Event handlers */
- function load () {
- checkForHome();
- loadLanguage();
-
- //load font size
- document.getElementById("fontsize").value = widget.preferenceForKey("font-size");
-
- if (widget.preferenceForKey("font-size") == "")
- document.getElementById("fontsize").value = "11 pt";
-
-
- var prefWidth = widget.preferenceForKey("pad-width");
- var prefHeight = widget.preferenceForKey("pad-height");
-
- if (prefWidth && prefWidth > 0 && prefHeight && prefHeight > 0) {
- window.width = prefWidth;
- window.height = prefHeight;
- window.resizeTo(prefWidth, prefHeight);
- }
-
- var prefPage = widget.preferenceForKey("open-page");
-
- var pageToShow = 1;
- if (prefPage && prefPage > 0 ) {
- pageToShow = prefPage;
- }
-
- setFontSize();
-
- // Load the first page
- openPage = pageToShow;
- loadPage(pageToShow);
- loadPageSelector();
- }
-
- function store() {
- savePage(openPage);
- }
-
- /* Neat fade effects */
- var showControls;
-
- function doBlur() {
- store();
- showControls = false;
- doFade();
- }
-
- function doFocus() {
- showControls = true;
- doFade();
- }
-
- /*
- since the dashboard sucks at giving focus, we need
- a few extra checks
- */
- function extraFocus() {
- if (!showControls)
- doFocus();
- }
-
- var fTools, fControls, fHider;
-
- function doFade() {
- clearInterval(fTools);
- fTools = qfade("tools");
-
- clearInterval(fControls);
- fControls = qfade("bottomcontrols");
-
- clearInterval(fHider);
- fHider = qfade("toolhider");
- }
-
- function getTO() {
- if (showControls)
- return 1;
- else
- return 0;
- }
-
- window.onblur = doBlur;
- window.onfocus = doFocus;
- widget.onhide = store;
- widget.onremove = store;
-
- var help_canvas;
-
- // Checks for and creates the Library folder where note pad pages are stored
- function checkForHome() {
- if (widget.system("ls ~/Library/NotePad",null).status==1) {
- widget.system("mkdir ~/Library/NotePad",null);
- }
- }
-
-
-
-
- /* Languages */
-
- var language = "english";
- function loadLanguage() {
- var l = widget.system('defaults read "Apple Global Domain" AppleLanguages',null).outputString;
- language = getLanguageToUse(splitLanguages(l));
-
- document.getElementById("deltext").innerHTML = getLocalString("delete sure");
- document.getElementById("printtext").innerHTML = getLocalString("print sure");
-
- document.getElementById("delok").innerHTML = getLocalString("delete");
- document.getElementById("printok").innerHTML = getLocalString("print");
-
- document.getElementById("delcancel").innerHTML = getLocalString("cancel");
- document.getElementById("printcancel").innerHTML = getLocalString("cancel");
-
- document.getElementById("deleteicon").title = getLocalString("delete");
- document.getElementById("printicon").title = getLocalString("print");
- document.getElementById("newicon").title = getLocalString("new page");
- document.getElementById("searchicon").title = getLocalString("search notes");
- }
-
- function splitLanguages(list) {
- var list = list.substr(1);
- list = list.substr(0,list.length-1);
- var langs = list.split(",");
-
- return langs;
- }
-
- function getLanguageToUse(langs) {
- for (var i = 0; i < langs.length; i++) {
- var l = langs[i];
-
- if (l.charAt(0) == ' ')
- l = l.substr(1);
-
- switch (l) {
- case "en":
- return "english";
- case "English":
- return "english";
-
- case "sv":
- return "swedish";
- case "Swedish":
- return "swedish";
-
- case "fr":
- return "french";
- case "French":
- return "french";
- }
- }
-
- return "english";
- }
-
- function getLocalString(value) {
-
- switch (value) {
-
- case "new page":
- if (language == "english")
- return "New page";
- else if (language == "french")
- return "Nouvelle page";
- else if (language == "swedish")
- return "Ny sida";
-
- case "delete sure":
- if (language == "english")
- return "Are you sure you want to delete this page?";
- else if (language == "french")
- return "Êtes-vous sûr de vouloir supprimer cette page?";
- else if (language == "swedish")
- return "Är du säker på att du vill radera sidan?";
-
- case "print sure":
- if (language == "english")
- return "Are you sure you want to print this page?";
- else if (language == "french")
- return "Êtes-vous sûr de vouloir imprimer cette page?";
- else if (language == "swedish")
- return "Är du säker på att du vill skriva ut sidan?";
-
- case "delete":
- if (language == "english")
- return "Delete";
- else if (language == "french")
- return "Effacer";
- else if (language == "swedish")
- return "Radera";
-
- case "print":
- if (language == "english")
- return "Print";
- else if (language == "french")
- return "Imprimer";
- else if (language == "swedish")
- return "Skriv ut";
-
- case "cancel":
- if (language == "english")
- return "Cancel";
- else if (language == "french")
- return "Annuler";
- else if (language == "swedish")
- return "Avbryt";
-
- case "search notes":
- if (language == "english")
- return "Search notes";
- else if (language == "french")
- return "Chercher";
- else if (language == "swedish")
- return "Sökning";
-
- case "daysleft_pre":
- if (language == "english")
- return "";
- else if (language == "french")
- return "Vous allez pouvoir utiliser ";
- else if (language == "swedish")
- return "";
-
- case "daysleft_mid":
- if (language == "english")
- return " will run without payment for ";
- else if (language == "french")
- return " de manière illimitée pour encore ";
- else if (language == "swedish")
- return " kommer att forts√§tta fungera gratis i ";
-
- case "daysleft_post":
- if (language == "english")
- return " more day";
- else if (language == "french")
- return " jour";
- else if (language == "swedish")
- return " dag";
-
- case "daysleft_plural":
- if (language == "english")
- return "s";
- else if (language == "french")
- return "s";
- else if (language == "swedish")
- return "ar";
-
- case "daysleft_thanks":
- if (language == "english")
- return "Thanks for using NotePad!";
- else if (language == "french")
- return "Merci d'utiliser NotePad!";
- else if (language == "swedish")
- return "Tack för att du använder NotePad!";
-
- case "buy":
- if (language == "english")
- return "Buy";
- else if (language == "french")
- return "Acheter";
- else if (language == "swedish")
- return "Köp";
-
- case "register":
- if (language == "english")
- return "Register";
- else if (language == "french")
- return "Enregistrer";
- else if (language == "swedish")
- return "Registrera";
- }
-
- }
-
-
-
- /* Page managing */
-
- // Save this page, and load another.
- function goPage(num) {
- savePage(openPage);
- openPage = num;
- loadPage(openPage);
- }
-
- // Load a page from disk and display it, or create a new page if it didn't exist.
- function loadPage(page) {
- var eDiv = document.getElementById("edit");
- var data = widget.system("/bin/cat "+getFileName(page),null).outputString;
- var title = getTitle(page);
-
- if (data != undefined) {
- document.getElementById("title").innerHTML = title;
- eDiv.value = data;
- showCurrentPage();
- } else {
- document.getElementById("title").innerHTML = "New page "+openPage;
- eDiv.value = getLocalString("new page")+' '+openPage;
- savePage(openPage);
- loadPageSelector();
- }
-
- widget.setPreferenceForKey(openPage, "open-page");
- // we don't want to keep the user waiting, so let's thread these as well
- setTimeout("showTitle()",5);
- setTimeout("updateNav()",6);
- }
-
- function updateNav() {
- if (openPage == 1)
- document.getElementById("prev").style.opacity = "0.2";
- else
- document.getElementById("prev").style.opacity = "0.5";
-
- if ( pageExists(openPage+1) )
- document.getElementById("next").style.opacity = "0.5";
- else
- document.getElementById("next").style.opacity = "0.2";
- }
-
- // Save a page to disk.
- function savePage(page) {
- var txt = document.getElementById("edit").value;
-
- if (openPage>0 && txt!='' && !(txt.substr(0,9)=='New page ' && txt.length<12)) {
- var writing = widget.system("/bin/cat > "+getFileName(page),forceAsync);
- writing.write(txt);
- writing.close();
- updatePageSelector(page);
- showTitle();
- }
- }
-
- // Delete a page from disk, and scootch other page numbers up
- function deletePage(page) {
- widget.system("/bin/rm "+getFileName(page),null);
-
- var max = document.getElementById("pagePopup").options.length;
- for (var p = page; p<max; p++) { // for (var p = page; pageExists(p+1); p++) {
- widget.system("/bin/mv "+getFileName(p+1)+" "+getFileName(p),null);
- }
-
- loadPageSelector();
- if ( (!pageExists(openPage)) && openPage>1) {
- openPage--;
- }
- loadPage(openPage);
- }
-
- function getTitle(page) {
- var data = widget.system("/usr/bin/head -n1 "+getFileName(page),null).outputString;
-
- if (data != undefined) {
- var title = data.substr(0,31);
-
- if (title != data)
- title = title + "...";
-
- return title;
- } else {
- return "empty";
- }
- }
-
- function showTitle() {
- if (document.getElementById("searchtab").style.display=="block")
- document.getElementById("title").innerHTML = getLocalString("search notes");
- else
- document.getElementById("title").innerHTML = quickTitle(); //getTitle(openPage);
- }
-
- /* Live title updating */
- var lastType = 0;
- function isTyping() {
- var d = new Date();
- var m = d.getMilliseconds();
-
- lastType = m;
- setTimeout("isStillTyping("+m+")",500);
- }
-
- function isStillTyping(m) {
- if (m == lastType)
- doUpdateTitle();
- }
-
- function doUpdateTitle() {
- document.getElementById("title").innerHTML = quickTitle();
- isUpdating = false;
- }
-
- function quickTitle() {
- var txt = document.getElementById("edit").value;
- var fl = firstLine(txt);
-
- if (fl != "")
- return fl;
-
- return txt.substr(0,31);
- }
-
- function firstLine(text) {
- var delim = text.indexOf("\n");
- return text.substr(text,delim+1);
- }
-
-
-
-
-
- /* Misc. file managing */
-
- // Where to save pages?
- function getFileName(page) {
- return "~/Library/NotePad/Page"+page+".txt";
- }
-
- // Does a page exist on disk?
- function pageExists(p) {
- return (widget.system("/bin/ls "+getFileName(p),null).outputString!=undefined);
- }
-
-
-
-
-
-
- /* Search */
-
- function togglesearch(opening) {
- store();
- toggleVisibility("edittab");
- toggleVisibility("searchtab");
- toggleVisibility("controls");
- toggleVisibility("searchicon");
- toggleVisibility("printicon");
- toggleVisibility("deleteicon");
- toggleVisibility("newicon");
- showTitle();
-
- if (opening == true)
- document.getElementById("searchtext").focus();
- }
-
- function showresult(page) {
- goPage(page);
- togglesearch();
- }
-
- var grepProc;
- function doSearch() {
- if (grepProc != undefined) {
- grepCompleted();
- grepProc.cancel();
- }
-
- var searchstring = document.getElementById("searchtext").value;
-
- if (searchstring == "") {
- parseGrep("");
- return;
- }
-
- /*
- Multi-byte search support (asian text keke ^_^)
- */
-
- var writing = widget.system("/bin/cat > ~/Library/Caches/NotePadSearch",forceAsync);
- writing.write(searchstring);
- writing.close();
-
- grepProc = widget.system("grep -i -m 1 -f ~/Library/Caches/NotePadSearch ~/Library/NotePad/*",grepCompleted);
-
- /*
- This line is for single-byte languages. It's faster.
- grepProc = widget.system("grep -i -m 1 \""+searchstring+"\" ~/Library/NotePad/*",grepCompleted);
- */
- }
-
- function grepCompleted() {
- parseGrep(grepProc.outputString);
- }
-
- function parseGrep(grepOutput) {
- var results = document.getElementById("searchresults");
- var s = "<br>";
-
- if (grepOutput != undefined) {
- var resultarray = grepOutput.split("\n");
-
- for (var i = 0; i < resultarray.length; i++) {
- var line = resultarray[i];
- var delim = line.indexOf(":");
- var path = line.substr(0,delim);
- var foundLine = line.substr(delim+1);
-
- j = path.lastIndexOf("e"); // e as in Page
-
- if (j > 0) {
- p = parseInt(path.substr(j+1,3));
-
- if (p != NaN) {
- link = "" + p + ". " + foundLine; //getTitle(p);
- link = link.link("javascript:showresult("+p+")");
- s = s + link + "<br> \n";
- }
- }
- }
- }
-
- results.innerHTML = s;
- }
-
-
-
-
-
-
- /* Manage the page selector */
- function loadPageSelector() {
- var eDiv = document.getElementById("pagePopup");
- eDiv.options.length = 0;
-
- for (var p = 1; pageExists(p); p++) {
- eDiv.options[p-1] = new Option(p+". " + getTitle(p),p);
- }
- showCurrentPage();
- }
-
- function updatePageSelector(p) {
- var eDiv = document.getElementById("pagePopup");
- eDiv.options[p-1] = new Option(p+". " + getTitle(p),p);
- showCurrentPage();
- }
-
- function showCurrentPage() {
- document.getElementById("pagePopup").value = openPage;
- document.getElementById("pagenumber").innerHTML = openPage;
- }
-
-
-
-
-
- /* Page flippers */
-
- // Next page flipper
- function nextPage() {
- if ( pageExists(openPage+1) )
- goPage(parseInt(openPage)+1);
- }
-
- // Previous page flipper
- function prevPage() {
- if (openPage > 1) {
- goPage(parseInt(openPage)-1);
- }
- }
-
- function newPage() {
- goPage( document.getElementById("pagePopup").options.length +1 );
- }
-
- function newPageDrop(event) {
- var text = null;
-
- try {
- text = event.dataTransfer.getData("text/plain");
- } catch (ex) { }
-
- if (text) {
- newPage();
- document.getElementById("edit").value = text;
- doUpdateTitle()
- }
-
- event.stopPropagation();
- event.preventDefault();
- }
-
-
- function dragenter (event)
- {
- event.stopPropagation();
- event.preventDefault();
- }
-
- function dragover (event)
- {
- event.stopPropagation();
- event.preventDefault();
- }
-
- function dragleave (event)
- {
- event.stopPropagation();
- event.preventDefault();
- }
-
-
-
-
-
-
-
-
-
- /* Dialogs */
-
- function deleteQuery() {
- toggleVisibility("deletedialog");
- toggleVisibility("controls");
- toggleVisibility("searchicon");
- toggleVisibility("printicon");
- toggleVisibility("newicon");
- }
-
- function deleteYes() {
- deleteQuery();
- deletePage(openPage);
- }
-
- function printQuery() {
- toggleVisibility("printdialog");
- toggleVisibility("controls");
- toggleVisibility("searchicon");
- toggleVisibility("deleteicon");
- toggleVisibility("newicon");
- }
-
- function printYes() {
- printQuery();
- printPage(openPage);
- }
-
-
-
-
-
- /* Utilities */
- function printPage(page) {
- widget.system("/usr/bin/lpr " + getFileName(page), null);
- //NotePlug.printText(document.getElementById("edit").value);
- }
-
-
-
- function waitCursor(what) {
- if (what)
- document.body.style.cursor="wait";
- else
- document.body.style.cursor="auto";
- }
-
- function toggleVisibility(what) {
- if (document.getElementById(what).style.display=="none")
- document.getElementById(what).style.display="block";
- else
- document.getElementById(what).style.display="none";
- }
-
-
- function forceRepaint() {
- var v = document.body.offsetHeight;
- }
-
- function forceAsync() { /* blank */ }
-
-
-
-
-
-
- /* Tutorial */
- var help_running = false;
-
- function getOffsetTop(element) {
- var top = 0;
- var el = element;
-
- do {
- top += el.offsetTop;
- el = el.parentNode;
- } while (el !== document.body);
-
- return top;
- }
-
- function getOffsetLeft(element) {
- var left = 0;
- var el = element;
-
- do {
- left += el.offsetLeft;
- el = el.parentNode;
- } while (el !== document.body);
-
- return left;
- }
-
- var help_canvas_pen, help_canvas_x_stretch, help_canvas_y_stretch;
-
- function showHelp() {
- help_running = true;
-
- hidePrefs();
-
- /* If the search tab is visible, hide it */
- if (document.getElementById('searchtab').style.display!="none")
- togglesearch(false);
-
- /* Hide dialog boxes */
- if (document.getElementById('printdialog').style.display!="none")
- printQuery();
-
- if (document.getElementById('deletedialog').style.display!="none")
- deleteQuery();
-
- document.getElementById("cover").style.display = "block";
- helpCircleEdit();
- }
-
- function helpCircleEdit() {
- circleObject('edit',
- function () {
- showHelpText(0,
- function () {
- setTimeout( "helpCircleNewIcon()", 10000);
- }
- )
- }
- );
- }
-
- function helpCircleNewIcon() {
- hideHelpText(0,
- function () {
- circleObject('newicon',
- function () {
- showHelpText(1,
- function () {
- setTimeout( "helpCircleDeleteIcon()", 5000)
- }
- )
- }
- )
- }
- );
- }
-
- function helpCircleDeleteIcon() {
- hideHelpText(1,
- function () {
- circleObject('deleteicon',
- function () {
- showHelpText(2,
- function () {
- setTimeout( "helpCirclePrintIcon()", 5000)
- }
- )
- }
- )
- }
- );
- }
-
- function helpCirclePrintIcon() {
- hideHelpText(2,
- function () {
- circleObject('printicon',
- function () {
- showHelpText(3,
- function () {
- setTimeout( "helpCircleSearchIcon()", 5000)
- }
- )
- }
- )
- }
- );
- }
-
- function helpCircleSearchIcon() {
- hideHelpText(3,
- function () {
- circleObject('searchicon',
- function () {
- showHelpText(4,
- function () {
- setTimeout( "helpCircleNavIcon()", 5000)
- }
- )
- }
- )
- }
- );
- }
-
- function helpCircleNavIcon() {
- hideHelpText(4,
- function () {
- circleObject('controls',
- function () {
- showHelpText(5,
- function () {
- setTimeout( "helpCircleGrowIcon()", 10000)
- }
- )
- }
- )
- }
- );
- }
-
- function helpCircleGrowIcon() {
- hideHelpText(5,
- function () {
- circleObject('grow',
- function () {
- showHelpText(6,
- function () {
- setTimeout( "helpThanks()", 4000)
- }
- )
- }
- )
- }
- );
- }
-
- function helpThanks() {
- hideHelpText(6,
- function () {
- document.getElementById("help_circle_canvas").style.display = "none";
- showHelpText(7,
- function () {
- setTimeout( "helpDone()", 4000)
- }
- )
- }
- );
- }
-
-
- function helpDone() {
- hideHelpText(7, null);
- document.getElementById("help_circle_canvas").style.display = "none";
- document.getElementById("cover").style.display = "none";
-
- showPrefs();
- }
-
-
-
- function cancelHelp() {
- help_running = false;
- document.getElementById("help_circle_canvas").style.display = "none";
- document.getElementById("help_text_"+language).style.display = "none";
- document.getElementById("cover").style.display = "none";
- }
-
- function handleKeyPress(e) {
- if (e.charCode == 27 && help_running) cancelHelp();
- }
-
- function circleObject(obj, callBack) {
- if (!help_running) return false;
-
- if (obj == new String(obj)) obj = document.getElementById(obj);
-
- help_canvas = document.getElementById("help_circle_canvas");
-
- help_canvas.style.display = "block";
- var help_context = help_canvas.getContext("2d");
-
- help_canvas.style.top = (getOffsetTop(obj) - 3) + "px";
- help_canvas.style.left = (getOffsetLeft(obj) - 3) + "px";
- help_canvas.style.bottom = "0 px";
- help_canvas.style.right = "0 px";
-
- help_context.lineWidth = 1;
- help_context.lineJoin = "bevel";
- help_context.lineCap = "round";
- help_context.strokeStyle = "rgba(255, 0, 0, 0.8)";
-
- help_context.clearRect(0, 0, 1000, 1000);
- help_context.save();
-
- if (parseInt(document.defaultView.getComputedStyle(obj, '').getPropertyValue("width")) > 20) {
- help_canvas_x_stretch = parseInt(document.defaultView.getComputedStyle(obj, '').getPropertyValue("width"))/30;
- } else {
- help_canvas_x_stretch = 1;
- }
-
- if (parseInt(document.defaultView.getComputedStyle(obj, '').getPropertyValue("height")) > 20) {
- help_canvas_y_stretch = parseInt(document.defaultView.getComputedStyle(obj, '').getPropertyValue("height"))/30;
- } else {
- help_canvas_y_stretch = 1;
- }
-
- help_context.scale(help_canvas_x_stretch, help_canvas_y_stretch);
-
- help_context.beginPath();
- help_context.moveTo(5, 10);
-
- var i=0;
-
- var inter = setInterval(
- function () {
- //alert(i);
- switch (i) {
- case 0:
- help_context.bezierCurveTo(5, 0, 20, 10, 20, 20);
- break;
- case 1:
- help_context.beginPath();
- help_context.moveTo(20, 10);
- help_context.bezierCurveTo(30, 20, 20, 30, 15, 20);
- break;
- case 2:
- help_context.beginPath();
- help_context.moveTo(20, 30);
- help_context.bezierCurveTo(10, 35, 5, 25, 5, 10);
- break;
- case 3:
- help_context.beginPath();
- help_context.moveTo(5, 25);
- help_context.bezierCurveTo(2, 7, 9, 10, 0, 0);
- break;
- //Default:
- case 4:
- clearInterval(inter);
- help_context.restore();
- if (callBack != null) callBack();
- break;
- }
- help_context.stroke();
- i++;
- }, 70);
- }
-
- function showHelpText(which, callBack) {
- if (!help_running) return false;
-
- var help_text = document.getElementById("help_text_"+language);
- help_text.style.display = "block";
-
- var messages = help_text.getElementsByTagName("div");
- if (which > 0) messages[which-1].style.opacity = 0;
-
- fade(messages[which], 0, 0.9,
- function() {
- //setTimeout("help_text_shadow.paint()", 100);
- callBack();
- });
- }
-
- function hideHelpText(which, callBack) {
- var help_text = document.getElementById("help_text_"+language);
-
-
- var messages = help_text.getElementsByTagName("div");
- //if (which > 0) messages[which-1].style.opacity = 0;
-
- fade(messages[which], 0.9, 0,
- function () {
- help_text.style.display = "none";
- callBack();
- });
- }
-
-
-
-
-
-
- /* Fade (for help text) */
- function fade(el, from, to, callBack) {
- if (el == new String(el)) el = document.getElementById(el);
- //so we can pass a string for the id or an element
-
- if (from == -1) // kalleboo mod
- from = el.style.opacity;
-
- var dif = Math.abs(to - from);
-
- var pi = Math.PI;
- var theta = 0;
-
- //if (to < from && el.style.opacity > 0) return;
-
- var inter = setInterval(
- function() {
- if (theta < 90) {
- theta += 10;
- if (to > from)
- var step = Math.sin((theta*pi)/180);
- else
- var step = Math.cos((theta*pi)/180);
- var opac = dif*step;
- el.style.opacity = Math.max(0.01, opac); //fixing safari glitch
- } else {
- el.style.opacity = to;
- clearInterval(inter);
- if (callBack != null) callBack();
- }
- }, 100);
- }
-
- /* Quicker fade (for hiding controls) */
- function qfade(el) {
- el = document.getElementById(el);
-
- var from = el.style.opacity;
- var to = getTO();
-
- var pi = Math.PI;
- var theta = 0;
-
- var inter = setInterval(
- function() {
- to = getTO();
-
- if (theta < 90) {
- theta += 20;
- if (to > from)
- var step = Math.sin((theta*pi)/180);
- else
- var step = Math.cos((theta*pi)/180);
-
- var opac = Math.abs(to - from) * step;
- el.style.opacity = Math.max(0.01, opac); //fixing safari glitch
- } else {
- el.style.opacity = getTO();
- clearInterval(inter); // inter
- }
- }, 50);
-
- return inter;
- }
-
-
-
-
- function setFontSize() {
- document.getElementById("edit").style.fontSize = document.getElementById("fontsize").value;
- widget.setPreferenceForKey(document.getElementById("fontsize").value, "font-size");
- }
-
-
-
-
- /* FLIP */
- function showPrefs() {
- flipped = true;
- var front = document.getElementById("front");
- var back = document.getElementById("back");
-
- if (window.widget)
- widget.prepareForTransition("ToBack"); // freezes the widget so that you can change it without the user noticing
-
- front.style.display="none"; // hide the front
- back.style.display="block"; // show the back
-
- if (window.widget)
- setTimeout ('widget.performTransition();', 0); // and flip the widget over
- }
-
- function hidePrefs() {
- fipped = false;
- var front = document.getElementById("front");
- var back = document.getElementById("back");
-
- if (window.widget)
- widget.prepareForTransition("ToFront"); // freezes the widget and prepares it for the flip back to the front
-
- back.style.display="none"; // hide the back
- front.style.display="block"; // show the front
-
- if (window.widget)
- setTimeout ('widget.performTransition();', 0); // and flip the widget back to the front
- }
-
-
-
-
-
-
- /* RESIZE */
- function minwidth() { return 258; }
- function minheight() { return 261; }
-
- function maxwidth() { return 570; }
- function maxheight() { return 600; }
-
- var lastPos; // tracks where the last mouse position was throughout the drag
-
- function mouseDown(event) {
-
- var x = event.x + window.screenX; // the placement of the click
- var y = event.y + window.screenY;
-
- document.addEventListener("mousemove", mouseMove, true); // begin tracking the move
- document.addEventListener("mouseup", mouseUp, true); // and notify when the drag ends
-
- lastPos = {x:x, y:y}; // track where the initial mouse down was, for later comparisons
- // the mouseMove function
-
- event.stopPropagation();
- event.preventDefault();
- }
-
- function mouseMove(event) {
-
- var screenX = event.x + window.screenX; // retrieves the current mouse position
- var screenY = event.y + window.screenY;
-
- var deltaX = 0; // will hold the change since the last mouseMove event
- var deltaY = 0;
-
- if ( (window.outerWidth + (screenX - lastPos.x)) >= 60 ) { // sets a minimum width constraint
- deltaX = screenX - lastPos.x; // if we're greater than the constraint,
- lastPos.x = screenX; // save the change and update our past position
- }
-
- if ( (window.outerHeight + (screenY - lastPos.y)) >= 25 ) { // setting contrains for the heght
- deltaY = screenY - lastPos.y;
- lastPos.y = screenY;
- }
-
- if (window.innerWidth+deltaX > maxwidth())
- deltaX = maxwidth()-window.innerWidth;
-
- if (window.innerWidth+deltaX < minwidth())
- deltaX = minwidth()-window.innerWidth;
-
- if (window.innerHeight+deltaY > maxheight())
- deltaY = maxheight()-window.innerHeight;
-
- if (window.innerHeight+deltaY < minheight())
- deltaY = minheight()-window.innerHeight;
-
- window.resizeBy(deltaX, deltaY); // resizes the widget to follow the mouse movement
-
- event.stopPropagation();
- event.preventDefault();
- }
-
- function mouseUp(event) {
- document.removeEventListener("mousemove", mouseMove, true);
- document.removeEventListener("mouseup", mouseUp, true);
-
- widget.setPreferenceForKey(window.outerWidth, "pad-width");
- widget.setPreferenceForKey(window.outerHeight, "pad-height");
-
- event.stopPropagation();
- event.preventDefault();
- }
-
- /* Reg */
-
- function register() {
- if (NotePad) NotePad.registerWidget();
- }
-
- function buy() {
- if (NotePad) NotePad.buyWidget();
- }
-
- function showNag(days_left) {
- //alert('days left (js): ' + days_left);
- isNagging = true;
-
- // show the register stickers on the back
- document.getElementById("backreground").style.display = "";
- document.getElementById("backbuynow").style.display = "";
- //
-
- document.getElementById("front").style.display = "none";
- document.getElementById("back").style.display = "none";
- window.resizeTo(341, 134);
-
- //I'll forgo doing this in a nice DOM way for the moment:
- var cont = document.createElement("div");
- cont.id = "buy_panel";
-
- var buy_p_text = document.createElement("div");
- buy_p_text.id = "buy_panel_text";
- cont.appendChild(buy_p_text);
-
- buy_p_text.innerHTML += getLocalString("daysleft_pre") + '<span id="widget_name">NotePad</span>' + getLocalString("daysleft_mid") + days_left + getLocalString("daysleft_post");
- if (10 - days_left != 1) buy_p_text.innerHTML += getLocalString("daysleft_plural");
- buy_p_text.innerHTML += '.<br />'+getLocalString("daysleft_thanks")+'\n';
- var buy_p_buts = document.createElement("div");
- buy_p_buts.id = "buy_buttons";
- cont.appendChild(buy_p_buts);
-
- buy_p_buts.innerHTML += '<a href="#" onclick="NotePad.buyWidget()">'+getLocalString("buy")+'</a>\n';
- buy_p_buts.innerHTML += '<a href="#" onclick="NotePad.registerWidget()">'+getLocalString("register")+'</a>\n';
-
- var counter = document.createElement("span");
- counter.id = "counter";
- counter.innerText = 7;
-
- buy_p_buts.appendChild(counter);
-
- document.body.appendChild(cont);
-
- var count_down = 7;
-
- var inter = setInterval(
- function () {
- if (--count_down >= 0) {
- counter.innerText = count_down;
- } else {
- clearInterval(inter);
- window.resizeTo(250, 230);
- if (!flipped) {
- document.getElementById("front").style.display = "block";
- } else {
- document.getElementById("back").style.display = "block";
- //document.getElementById("register_buy").style.display = "block";
- }
-
- document.body.removeChild(cont);
- }
- }, 1000);
- }